<?php
namespace Common\Model;

use Think\Model;

class SystemDictModel extends \BaseModel
{

    /**
     * 字典
     * @param  integer dict
     * @return string
     */
    public function load($name, $value, $remark)
    {
        /**********有值的时候，需要更新到字典*******/
        if ($value) {
            $row = array(
                'name' => $name,
                'value' => json_encode($value),
                'remark' => $remark,
                'addtime' => time(),
            );
            $r = $this->where(array('name' => $name))->select();
            if ($r) {
                return $this->where(array('name' => $name))->save($row);
            } else {
                return $this->add($row);
            }
        }
        /**********返回字典的值*******/
        if ($name) {
            $data = $this->find($name);
        }
        /****字典没有值****/
        if (!$data) {
            return $data;
        }
        /***********字典查到值*******/
        $data['value'] = json_decode($data['value'], true);
        /*******如果是一维数据*****/
        return $data['value'];
    }


}
 